﻿@{
    ViewBag.Title = "考核参数";
}
<div data-ng-app="myapp" data-ng-controller="myCtrl">
     <div class="container">
         <div data-ng-repeat="g in groups">
             <br />
             <div class="panel panel-default">
                 <div class="panel-heading">
                     <h5>{{g.key}}(%)</h5>
                 </div>
                 <div class="panel-body">
                     <div class="col-sm-4" data-ng-repeat="para in g.list">
                         <form class="form-horizontal" role="form">
                             <div class="form-group">
                                 <label for="起点进度" class="col-sm-4 control-label">{{para.Content}}&nbsp;&nbsp;</label>
                                 <div class="col-sm-8">
                                     <input type="number" step="1" class="form-control" min="0" max="100" data-ng-model="para.Value">
                                 </div>
                             </div>
                         </form>

                     </div>
                 </div>
             </div>
         </div>
         <div class="row">
             <div class="pull-right col-sm-2">
                 <a class="btn btn-primary btn-block" data-ng-click="save()" data-ng-disabled="!canSave">提 交</a>
             </div>
         </div>

     </div>
</div>


<script type="text/javascript">
    var myapp = angular.module('myapp', []);
    myapp.controller('myCtrl', ['$scope', '$timeout', '$http', function ($scope, $timeout, $http)
    {
        $scope.groups = JSON.parse('@Html.Raw(ViewBag.groups)');
        $scope.prjId = '@ViewBag.PrjId';
        $scope.canSave = false;
        var counter = 0;
        var items = [];
        function getItems() {
            items = [];
            $scope.groups.forEach(function (item) {
                item.list.forEach(function (it) {
                    items.push(it);
                    if (!it.Value || it.Value <= 0 || it.Value >= 100) {
                        $scope.canSave = false;
                    }
                });
            });
        }
        $scope.$watch('groups', function () {
            counter++;         
            if (counter === 1) return;
            $scope.canSave = true;
            getItems();
        }, true);
        $scope.save = function () {
            $http({
                url: '@Url.Action("updatePara","DoAssess")',
                method: 'post',
                data: {
                    jsonArray: JSON.stringify(items),
                    prjId: $scope.prjId
                }
            }).success(function (data) {
                //成功
                alert("保存成功!");
            });

        };
  

    }]);
</script>